package com.xckj.teacher.ui.activity

import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.LogUtils
import com.xckj.teacher.R
import com.xckj.teacher.databinding.ActivityPersonalInformationBinding
import com.xckj.teacher.framework.BaseActivity
import com.xckj.teacher.presenter.MainPresenter
import com.xckj.teacher.ui.appViewModel
import com.xckj.teacher.ui.fragment.TakePhotoDialog
import com.xckj.teacher.util.CacheUtil
import com.xckj.teacher.util.CustomBindAdapter
import com.xckj.teacher.util.startActivity


/**
 * 个人信息
 */
class PersonDataActivity : BaseActivity<ActivityPersonalInformationBinding>() {
    private val presenter: MainPresenter by lazy { MainPresenter(this) }


    override fun setStatusBarColor(): Int {
        return R.color.f7f8fa
    }

    inner class ProxyClick {
        fun back() {
            finish()
        }

        fun changePass() {
            startActivity<ChangePassActivity>()
        }

        fun phone() {
            startActivity<CurrentPhoneActivity>("phone" to "${dataBinding.data?.mobile}")
        }

        fun logout() {
            CacheUtil.clearAll()
            startActivity<LoginActivity>()
            ActivityUtils.finishAllActivities()
        }

        fun update() {
            TakePhotoDialog {
                dataBinding.data = appViewModel.userInfoData.value
            }.show(supportFragmentManager, "")
        }
    }

    override fun loadLayout(): Int {
        return R.layout.activity_personal_information
    }

    override fun initData() {
        presenter.getUserInfo()
        dataBinding.click = ProxyClick()
    }

    override fun setListener() {
        appViewModel.lccal.observe(this) {
            LogUtils.e("wwwww")
            CustomBindAdapter.circleImageUrl(dataBinding.ivAvatar, it)
        }
        appViewModel.userInfoData.observe(this) {
            dataBinding.data = it
        }
    }

    override fun onResume() {
        super.onResume()
        dataBinding.data = appViewModel.userInfoData.value
    }
}